package com.justinwang4.androidservicedemo.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.justinwang4.androidservicedemo.R;
import com.justinwang4.androidservicedemo.services.MyService;

public class MyServiceActivity extends AppCompatActivity {

    private Button btnStartService;
    private Button btnStopService;

    private Button btnBindService;
    private Button btnUnbindService;

    private Intent intent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_service);

        intent = new Intent(MyServiceActivity.this, MyService.class);

        btnStartService = findViewById(R.id.btn_start_service);
        btnStartService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MyServiceActivity.this, "start service...", Toast.LENGTH_SHORT).show();
                startService(intent);
            }
        });

        btnStopService = findViewById(R.id.btn_stop_service);
        btnStopService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MyServiceActivity.this, "stop service...", Toast.LENGTH_SHORT).show();
                stopService(intent);
            }
        });

        btnBindService = findViewById(R.id.btn_bind_service);
        btnBindService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MyServiceActivity.this, "bind service...", Toast.LENGTH_SHORT).show();
            }
        });

        btnUnbindService = findViewById(R.id.btn_unbind_service);
        btnUnbindService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MyServiceActivity.this, "unbind service...", Toast.LENGTH_SHORT).show();
            }
        });

    }

}
